package ar.uade.edu.fain.ad.client.swing.util.xml;

import java.io.FileInputStream;
import java.io.IOException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

public class RemitoXmlReader {

	private final String path;

	public RemitoXmlReader(String path) {
		super();
		this.path = path;
	}
	
	public String getPath() {
		return path;
	}

	public RemitoXml leer() throws IOException, FormatoInvalidoException {
		try {
			final JAXBContext context = JAXBContext.newInstance(
					getClass().getPackage().getName());
			final FileInputStream fileInputStream = 
					new FileInputStream(getPath());
			return (RemitoXml) context.createUnmarshaller()
					.unmarshal(fileInputStream);
		} catch (JAXBException e) {
			e.printStackTrace(System.err);
			throw new FormatoInvalidoException(
					"El archivo no puede ser decodificado.", e);
		} 

	}
	
	
}
